package ex2.trans;

import ex2.Employee;
import ex2.PaymentClassification;
import ex2.PayrollDatabase;
import ex2.Transaction;
import ex2.classification.CommissionedfClassification;
import ex2.classification.SalesReceipt;
import ex2.exception.NoSuchEmployeeException;
import ex2.exception.NotCommissionedClsaaificationException;

public class SalesReceiptTransaction implements Transaction {

    private int empId;
    private String date;
    private double amount;

    public SalesReceiptTransaction(int empId, String date, double amount) {
        this.empId = empId;
        this.date = date;
        this.amount = amount;

    }

    @Override
    public void execute() {
        Employee e = PayrollDatabase.getEmployee(empId);
        if (e == null) {
            throw new NoSuchEmployeeException();
        }
        PaymentClassification pc = e.getPaymentClassification();
        if (pc instanceof CommissionedfClassification) {
            CommissionedfClassification cc = (CommissionedfClassification) pc;
            SalesReceipt sr = new SalesReceipt(date, amount);
            cc.addSalesReceipt(sr);
        } else {
            throw new NotCommissionedClsaaificationException();
        }

    }

}
